//获取风机编号
var search=window.location.search;
$('.heal_u a').eq(0).attr('href','health.html'+search);
$('.heal_u a').eq(1).attr('href','effect.html'+search);
var num=search.substring(search.indexOf('=')+1);

var base=document.getElementById("base_e");
var oCl=document.getElementById('canvas_l');
var oCr=document.getElementById('canvas_r');
var colony=document.getElementById("colony_e");
var mark = document.getElementById("mark_e");
var loss=document.getElementById('loss_e');
var timer=null;
var oH=document.getElementById('history');

var setLoading={
    text: '数据加载中',
    color: '#fff',
    textColor: '#fff',
    maskColor: 'rgba(255, 255, 255, 0)',
    zlevel: 0
};
/*效能信息*/
//基线曲线和集群曲线基本配置
var effectOption={
        title: {
            text: '基线曲线',
            textStyle: {
                color: '#fff',
                fontSize: 16
            },
            left: 30
        },
        legend: {
            orient: 'horizontal',
            right: '5%',
            itemWidth: 10,
            itemHeight: 10
        },
        data: [{
            name: '实时风功率',
            icon: 'rect',
            textStyle: {
                color: '#fff'
            }
        }, {
            name: '风功率基线',
            icon: 'rect',
            textStyle: {
                color: '#fff'
            }
        }],
        grid: {
            left: '5%',
            right: '10%',
            bottom: '0',
            containLabel: true
        },
        xAxis: {
            name: '(m/s)',
            nameTextStyle: {
                color: '#e6e6e6'
            },
           //max: 20,
            min: 0,
            type: 'value',
            scale: true,
            splitNumber: 20,
            axisLabel: {
                interval: 1,
                textStyle: {
                    color: '#fff'
                }
            },
            splitLine: {
                show: false,
                lineStyle: {
                    // 使用深浅的间隔色
                    color: '#ccc'
                }
            }
        },
        yAxis: {
            name: '(kW)',
            nameTextStyle: {
                color: '#e6e6e6'
            },
            gridIndex: 0,
            min:-5,
            type: 'value',
            position: 'left',
            offset: 0,
            axisLine: {
                lineStyle: {
                    color: '#2c2c2d'
                }
            },
            axisLabel: {
                interval: 8,
                textStyle: {
                    color: '#e6e6e6'
                }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    // 使用深浅的间隔色
                    color: 'rgba(255,255,255,0.15)'
                }
            }
        },
        series: [{
            name: 'scatter',
            type: 'scatter',
            symbolSize: 3,
            label: {
                emphasis: {
                    show: true
                }
            },
            itemStyle: {
                normal: {
                    color: '#6363f0'
                }
            },
            data:[] //data.power_scatter
        },
            {
            name: '风功率基线',
            "type": "line",
            smooth: true,
            symbol: 'none',
            zlevel: 2,
            "itemStyle": {
                "normal": {
                    "color": "#119c64",
                    borderWidth: 3
                }
            },
            "data":[] // data.power_baseline
        }, {
            name: '实时风功率',
            "type": "line",
            smooth: true,
            symbol: 'none',
            zlevel: 4,
            "itemStyle": {
                "normal": {
                    "color": "#802525",
                    borderWidth: 2
                }
            },
            lineStyle: {
                normal: {
                    color: '#802425',
                    width: 2
                }
            },
            "data":[] //data.Power_Real
        } ]
    };
/*基线曲线*/
var baseLine=echarts.init(base);
baseLine.showLoading(setLoading);
baseLine.setOption(effectOption);
$.ajax({
    //后面需要传日期
    url:URL+'?code=7&serial_num='+num+'&code2=1',
    success: curve_success1
});
function curve_success1(data){
    baseLine.hideLoading();
    var data=eval('('+data+')');
    baseLine.setOption({
        series:[
            {name:'scatter',data:data.power_scatter},
            {name:'风功率基线',data:data.power_baseline},
            {name:'实时风功率',data:data.Power_Real}
        ]
    })
}

/*集群曲线*/
var colonyLine=echarts.init(colony);
colonyLine.showLoading(setLoading);
colonyLine.setOption(effectOption);
$.ajax({
    //后面需要传日期
    url:URL+'?code=7&serial_num='+num+'&code2=2',
    success: curve_success2
});
function curve_success2(data){
    colonyLine.hideLoading();
    var data=eval('('+data+')');
    //$.fn.colonyLine(colony,'集群曲线',data);
    colonyLine.setOption({
        title:{
            text:'集群曲线'
        },
        series:[
            {name:'scatter',data:data.power_scatter},
            {name:'风功率基线',data:data.power_baseline},
            {name:'实时风功率',data:data.Power_Real}
        ]
    })
}

/*风功率损失分析*/
var lossOption = {
        title: {
            text: '风功率损失分析',
            textStyle: {
                color: '#fff',
                fontSize: 16
            },
            left: 30,
        },
        legend: {
            orient: 'horizontal',
            right: '30',
            itemWidth: 10,
            itemHeight: 10,
            width: 230,
            data: [{
                name: '待机',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }, {
                name: '性能衰退',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }, {
                name: '故障停机',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }, {
                name: '电网限电',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }, {
                name: '主动维护停机',
                icon: 'rect',
                textStyle: {
                    color: '#fff'
                }
            }]
        },

        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                textStyle: {
                    color: "#fff"
                }
            },
        },
        grid: {
            left: '10%',
            right: '10%',
            bottom: '10%',
        },
        "calculable": true,
        "xAxis": [{
            name: '(时间)',
            nameTextStyle: {
                color: '#fff',
            },
            "type": "category",
            "axisLine": {
                lineStyle: {
                    color: '#29292b'
                }
            },
            "splitLine": {
                "show": false
            },
            "axisTick": {
                "show":true,
                "interval":1,
                "length":3,
                alignWithLabel:true

            },
            "axisLabel": {
                "interval": 1,
                textStyle: {
                    color: '#e6e6e6',
                }
            },
            data: []//['3/15', '3/16', '3/17', '3/18', '3/19', '3/20', '3/21'],
        }],
        "yAxis": [{
            //max: 1,
            nameTextStyle: {
                color: '#ccc',
            },
            "splitLine": {
                "show": false
            },
            "axisLine": {
                lineStyle: {
                    color: '#29292b'
                }
            },
            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,
                textStyle: {
                    color: '#e6e6e6',
                },

            },
            "splitArea": {
                "show": false
            },
            splitLine: {
                show: true,
                lineStyle: {
                    // 使用深浅的间隔色
                    color: 'rgba(255,255,255,0.15)',
                }
            },

        }, {
            position: 'right',
            offset: 0,
            axisLine: {
                lineStyle: {
                    color: '#2e2d2e'
                }
            }
        }],
        "series": [{
                "name": "待机",
                "type": "bar",
                "stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                "itemStyle": {
                    "normal": {
                        "color": "#21c6fb",
                        "label": {
                            "show": false,
                            "textStyle": {
                                "color": "#fff"
                            },
                            formatter: function(p) {
                                return p.value > 0 ? (p.value) : '';
                            }
                        }
                    }
                },
                "data": []
            },
            {
                "name": "性能衰退",
                "type": "bar",
                "stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                "itemStyle": {
                    "normal": {
                        "color": "#109ac7",
                        "barBorderRadius": 0,

                    }
                },
                "data":[] 
                // [
                //     0.01,
                //     0.02,
                //     0.02,
                //     0.01,
                //     0.02,
                //     0.02,
                //     0.02,

                // ]
            }, {
                "name": "故障停机",
                "type": "bar",
                "stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                "itemStyle": {
                    "normal": {
                        "color": "#0e6f8e",
                        "barBorderRadius": 0,

                    }
                },
                "data": []
                // [
                //     0.01,
                //     0.01,
                //     0.01,
                //     0.01,
                //     0.01,
                //     0.01,
                //     0.01,

                // ]
            }, {
                "name": "电网限电",
                "type": "bar",
                "stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                "itemStyle": {
                    "normal": {
                        "color": "#16728f",
                        "barBorderRadius": 0,

                    }
                },
                "data":[] 
                // [
                //     0.02,
                //     0.05,
                //     0.06,
                //     0.04,
                //     0.05,
                //     0.04,
                //     0.03,

                // ]
            }, {
                "name": "主动维护停机",
                "type": "bar",
                "stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                "itemStyle": {
                    "normal": {
                        "color": "#11586f",

                    }
                },
                "data":[] 
                // [
                //     0.00,
                //     0.00,
                //     0.00,
                //     0.00,
                //     0.00,
                //     0.00,
                //     0.00,

                // ]
            }, {
                "name": "总数",
                "type": "line",
                //"stack": "总量",
                "barWidth": 30,
                "barCategoryGap":"10",
                symbolSize: 10,
                symbol: 'circle',
                "itemStyle": {
                    "normal": {
                        "color": "#d0c75d",
                        "barBorderRadius": 0,

                    }
                },
                "data":[] 
                // [
                //     0.0,
                //     0.0,
                //     0.0,
                //     0.0,
                //     0.0,
                //     0.0,
                //     0.0,

                // ]
            },
        ]
    };
var lossLine=echarts.init(loss);
lossLine.setOption(lossOption);
lossLine.showLoading(setLoading);
$.ajax({
    url:URL+'?code=7&serial_num='+num+'&code2=3',
    success:function(data){
        lossLine.hideLoading();
        var data=eval('('+data+')');
        lossLine.setOption({
            xAxis:[{data: data.time}],
            series:[
                {name:'待机',data:data.Stop},
                {name:'性能衰退',data:data.Perfor},
                {name:'故障停机',data:data.Fault},
                {name:'电网限电',data:data.LimitElec},
                {name:'主动维护停机',data:data.Maintain},
                {name:'总数',data:data.sum}
            ]
        })
        lossLine.on('click',function(params){
            console.log(params.name);
            baseLine.showLoading(setLoading);
            colonyLine.showLoading(setLoading);
            $.ajax({
                //基线曲线
                url:URL+'?code=7&serial_num='+num+'&code2=1&data='+params.name,
                success: curve_success1
            });
            $.ajax({
                //集群曲线
                url:URL+'?code=7&serial_num='+num+'&code2=2&data='+params.name,
                success: curve_success2
            });
        })
        
    }
})
//风机集群对标
var historyOption= {
    backgroundColor: '#464646',
    title: {
        text: '效能集群对标历史曲线',
        textStyle: {
            color: '#fafafa',
            fontSize: 11
        },
        x: '20',
        y: '20'
    },
    "tooltip": {
        "trigger": "axis",
        "axisPointer": {
            textStyle: {
                color: "#fff"
            }
        }
    },
    grid: {
        left: '5%',
        right: '10%',
        bottom: '10',
        containLabel: true

    },
    "calculable": true,
    "xAxis": [{
        show:true,
        "name": '(时间)',
        "nameTextStyle": {
            color: '#fff',
        },
        "type": "category",
        "axisLine": {
            lineStyle: {
                color: '#2d2c2d'
            }
        },
        "splitLine": {
            "show": false
        },
        "axisTick": {
            "show":true,
            "interval":6,
        },
        "axisLabel": {
            "interval": 6,
            textStyle: {
                color: '#e6e6e6',
            },

        },
        "data":[]// data.time
    }],
    'splitLine':{
        show:true
    },
    "yAxis": [{
        "min":0.5,
        "type": "value",
        "axisLine": {
            lineStyle: {
                color: '#2d2c2d'
            }
        },
        "axisTick": {
            "show": false
        },
        "axisLabel": {
            "interval": 0,
            textStyle: {
                color: '#e6e6e6'
            }
        },
        "splitArea": {
            "show": false
        },
        splitLine: {
            show: true,
            lineStyle: {
                // 使用深浅的间隔色
                color: 'rgba(255,255,255,0.15)'
            }
        }
    }, {
        position: 'right',
        offset: 0,
        axisLine: {
            lineStyle: {
                color: '#2e2d2e'
            }
        }
    }],
    "series": [{
        "name": "待机",
        "type": "bar",
        "stack": "总量",
        "barMaxWidth": 15,
        "barGap": "10%",
        "markLine": {
            data: [{
                name: '平均线',
                type: 'average',
                lineStyle: {
                    normal: {
                        color: '#0eb1e6'
                    }
                }
            } ]
        },
        "itemStyle": {
            normal: {
                //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                color: 'rgb(14,177,230)'
            }
        },
        "data":[]//data.history_average 
    }]
};
var historyLine=echarts.init(oH);
historyLine.setOption(historyOption);

var markOption={
    title: {
        text: '风机集群对标',
        textStyle: {
            color: '#fff',
            fontSize: 16
        },
    },
    legend: {
        orient: 'horizontal',
        itemWidth: 10,
        itemHeight: 10,
    },
    "tooltip": {
        "trigger": "axis",
        "axisPointer": {
            textStyle: {
                color: "#fff"
            }
        },
    },
    grid: {
        left: '5%',
        right: '10%',
        bottom: '0',
        containLabel: true
    },
    "calculable": true,
    "xAxis": [{
        name: '(风机编号)',
        nameTextStyle: {
            color: '#fff',
        },
        "type": "category",
        "axisLine": {
            lineStyle: {
                color: '#2d2c2d'
            }
        },
        "splitLine": {
            "show": false
        },
        "axisTick": {
            "show": false
        },
        "splitArea": {
            "show": false
        },
        "axisLabel": {
            "interval": 0,
            textStyle: {
                color: '#e6e6e6',
            },

        },
        "data":[]
    }],
    "yAxis": [{
        "type": "value",
        "axisLine": {
            lineStyle: {
                color: '#2d2c2d'
            }
        },
        "axisTick": {
            "show": false
        },
        "axisLabel": {
            "interval": 0,
            textStyle: {
                color: '#e6e6e6',
            },
        },
        splitLine: {
            show: true,
            lineStyle: {
                // 使用深浅的间隔色
                color: 'rgba(255,255,255,0.15)',
            }
        },
    }, {
        position: 'right',
        offset: 0,
        axisLine: {
            lineStyle: {
                color: '#2e2d2e'
            }
        }
    }, ],
    "series": [{
        "name": "平均值",
        "type": "bar",
        "stack": "总量",
        //"barMaxWidth": 15,
        "barGap": "10%",
        "markLine": {
            silent: true,
            symbol: '',
            data: [{
                name: '平均线',
                type: 'average',
                lineStyle: {
                    normal: {
                        color: '#0eb1e6'
                    }
                },
            }, ]
        },
        "itemStyle": {
            normal: {},
        },
        "data":[]

    } ]
};
var markLine=echarts.init(mark);
markLine.showLoading(setLoading);
markLine.setOption(markOption);
$.ajax({
    url:URL+'?code=7&serial_num='+num+'&code2=4',
    success:function(data){
        markLine.hideLoading();
        var data=eval('('+data+')');
        markLine.setOption({
            xAxis:[{
                data:data.name
            }],
            series:[
                {"name": "平均值",
                "itemStyle": {
                    normal: {
                        //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                        color: function(params) {
                            var color = 'rgb(208,199,93)';
                            var colorList = ['rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)','rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)', 'rgb(14,177,230)'];
                            colorList.splice(findInArr(num, data.name), 0, color);
                            return colorList[params.dataIndex];
                        }
                    },
                },
                data:data.average
                }
            ]
        })
        markLine.on('click',function(params) {
            historyLine.showLoading(setLoading);
            $('.rank').find('li').eq(params.dataIndex).css({'background':'#ccc','color':'#000'}).siblings().css({'background':'none','color':'#7f7f7f'});
            if (params.dataIndex == findInArr(num, data.name)) {
                if(oH.style.display=='none'){
                    oH.style.display='block';
                }else{
                    oH.style.display='none';
                }
                $.ajax({
                    url:URL+'?code=7&serial_num='+num+'&code2=5',
                    success:function(data){
                        historyLine.hideLoading();
                        var data=eval('('+data+')');
                        historyLine.setOption({
                            "xAxis":[
                                {name:'(时间)',data:data.time}
                            ],
                            "series":[
                                {name:'待机',data:data.history_average}
                            ]
                        });
                    }
                })
            }
        });
    }
});



$.fn.extend({
    canvasShadow: function(canvasName, arrData1, arrData2) {
        var gd = canvasName.getContext('2d');
       
        gd.strokeStyle ='rgba(0,0,0,.3)';
        gd.lineWidth =2;
        var arr = arrData1.concat(arrData2.reverse());
        gd.clearRect(0,0,2.1 * 20, 200 - 16.44 / 12.5);
        gd.moveTo(2.1 * 20, 200 - 16.44 / 12.5);
        for (var i = 1; i < arr.length; i++) {
            gd.clearRect(0,0,arr[i][0] * 20, (200 - (arr[i][1] / (12.5))));
            gd.lineTo(arr[i][0] * 20, (200 - (arr[i][1] / (12.5))));
        }
        gd.fillStyle = 'rgba(255,255,255,.1)';
        gd.fill();
        //gd.closePath();
        gd.stroke();
    }
})






